import request from '@/utils/request'

export function getMigrateDiff(data) {
    return new Promise((resolve, reject) => {
        request({
            url: '/migrate/diff/list',
            method: 'get',
            params: data
        }).then(res =>{
            res.data.data.results = res.data.data && res.data.data.results.map(item => {
                let selectTargetArchs = localStorage.getItem('selectTargetArchs')
                if(selectTargetArchs) {
                    selectTargetArchs = JSON.parse(selectTargetArchs)
                } else {
                    selectTargetArchs = {}
                }
                if(selectTargetArchs[String(item.id)]) {
                    item.targetArch = selectTargetArchs[String(item.id)]
                } else {
                    item.targetArch = "V10(SP1)-x86_64";
                }
                
                return item
            })
            resolve(res);
        })
    })
}

export function downloadMigrateDiff(data) {
    return request({
        url: '/migrate/diff/download',
        method: 'get',
        responseType: 'blob',
        params: data
    })
}

export function deleteMigrateDiff(data) {
    return request({
        url: '/migrate/diff',
        method: 'delete',
        params: data
    })
}

export function getMigrateDiffStatus(data) {
    return request({
        url: '/migrate/diff/status',
        method: 'get',
        params: data
    })
}

export function updateMigrateConfigure(data) {
    return request({
        url: '/migrate/diff/check/update',
        method: 'put',
        data
    })
}

export function issueMigrateConfigure(data) {
    return request({
        url: '/migrate/diff/check/issue',
        method: 'post',
        data
    })
}

export function createMigrateConfigure(data) {
    return request({
        url: '/migrate/diff/check/create',
        method: 'post',
        data
    })
}

export function getMigrateConfigure(data) {
    return new Promise((resolve, reject) => {
        request({
            url: '/migrate/diff/check/list',
            method: 'get',
            params: data
        }).then(res => {
            res.data.data.results = res.data.data && res.data.data.results.map(item => {
                item.edit = false;
                return item
            })
            resolve(res);
        })
    })
}

export function getMigrateConfigureHosts(data) {
    return request({
        url: '/migrate/diff/check/hosts',
        method: 'get',
        params: data
    })
}

export function downloadMigrateConfigure(data) {
    return request({
        url: '/migrate/diff/check/export',
        method: 'get',
        responseType: 'blob',
        params: data
    })
}

export function deleteMigrateConfigure(data) {
    return request({
        url: '/migrate/diff/check/delete',
        method: 'delete',
        data
    })
}

export function getMigrateClassInfo() {
    return request({
        url: '/migrate/diff/check/classinfo',
        method: 'get'
    })
}